﻿using ERPEF.Model;
using ERPIService;
using Microsoft.EntityFrameworkCore;
using S4Project;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERPService
{
    public class sal_SalesOrderService : sal_SalesOrderIService
    {
        private readonly MyDbContext MyDbContext;
        public sal_SalesOrderService(MyDbContext myDb)
        {
            this.MyDbContext = myDb;
        }

        public Task<int> Add(sal_sales_orders sal_Sales_Orders)
        {
            MyDbContext.sal_sales_orders.Add(sal_Sales_Orders);
            return MyDbContext.SaveChangesAsync();
        }

        public async Task<int> Delete(int so_id)
        {
            var del = MyDbContext.sal_sales_orders.Find(so_id);
            if (del != null)
            {
                del.IsDeleted = true;
                 await MyDbContext.SaveChangesAsync();
                return 1;
            }
            return 0;
        }

        //主表查询
        public Task<List<sal_sales_orders>> Query()
        {
            return MyDbContext.sal_sales_orders.Where(s=>s.IsDeleted == false).ToListAsync();
        }

        public Task<int> Update(sal_sales_orders sal_Sales_Orders)
        {
            MyDbContext.sal_sales_orders.Update(sal_Sales_Orders);
            return  MyDbContext.SaveChangesAsync();
        }
    }
}
